﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using Fulcrum.ControlGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.ControlGenerator
{
    [TestClass]
    public class DependencyPropertyDataContextTests
    {
        public DependencyPropertyDataContextTests()
        {
            // nothing
        }

        [TestMethod]
        public void TestChangedMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("OnBarChanged", dependencyProperty.ChangedMethodName);
        }

        [TestMethod]
        public void TestCoerceMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("OnCoerceBarProperty", dependencyProperty.CoerceMethodName);
        }

        [TestMethod]
        public void TestCoerceValue()
        {
            var config = CreateConfiguration();
            config.CoerceValue = true;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(true, dependencyProperty.CoerceValue);
        }

        [TestMethod]
        public void TestDefaultValue()
        {
            var config = CreateConfiguration();
            config.DefaultValue = "default";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("default", dependencyProperty.DefaultValue);
        }

        [TestMethod]
        public void TestDependencyPropertyKeyName()
        {
            var config = CreateConfiguration();
            config.IsReadOnly = true;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarPropertyKey", dependencyProperty.DependencyPropertyKeyName);
        }

        [TestMethod]
        public void TestDependencyPropertyName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarProperty", dependencyProperty.DependencyPropertyName);
        }

        [TestMethod]
        public void TestDescription()
        {
            var config = CreateConfiguration();
            config.Description = "a description";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("a description", dependencyProperty.Description);
        }

        [TestMethod]
        public void TestTypeConverter()
        {
            var config = CreateConfiguration();
            config.TypeConverter = "MyConverter";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("MyConverter", dependencyProperty.TypeConverter);
        }

        [TestMethod]
        public void TestEventName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarChanged", dependencyProperty.EventName);
        }

        [TestMethod]
        public void TestIsReadOnly()
        {
            var config = CreateConfiguration();
            config.IsReadOnly = true;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(true, dependencyProperty.IsReadOnly);
        }

        [TestMethod]
        public void TestLocalizationCategory()
        {
            var config = CreateConfiguration();
            config.LocalizationCategory = LocalizationCategory.Font;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(LocalizationCategory.Font, dependencyProperty.LocalizationCategory);
        }

        [TestMethod]
        public void TestLocalizationModifiability()
        {
            var config = CreateConfiguration();
            config.LocalizationModifiability = Modifiability.Modifiable;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(Modifiability.Modifiable, dependencyProperty.LocalizationModifiability);

        }

        [TestMethod]
        public void TestLocalizationReadability()
        {
            var config = CreateConfiguration();
            config.LocalizationReadability = System.Windows.Readability.Unreadable;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(Readability.Unreadable, dependencyProperty.LocalizationReadability);
        }

        [TestMethod]
        public void TestMetadataOptions()
        {
            var config = CreateConfiguration();
            config.MetadataOptions = new string[] { "abc", "xyz" };

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreNotSame(config.MetadataOptions, dependencyProperty.MetadataOptions);
            CollectionAssert.AreEqual((ICollection)config.MetadataOptions, (ICollection)dependencyProperty.MetadataOptions);
        }

        [TestMethod]
        public void TestName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("Bar", dependencyProperty.Name);
        }

        [TestMethod]
        public void TestProvideSetterDefault()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(false, dependencyProperty.ProvideSetter);
        }

        [TestMethod]
        public void TestProvideSetterFalse()
        {
            var config = CreateConfiguration();
            config.ProvideSetter = false;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(false, dependencyProperty.ProvideSetter);
        }

        [TestMethod]
        public void TestRemarks()
        {
            var config = CreateConfiguration();
            config.Remarks = "a remark";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("a remark", dependencyProperty.Remarks);
        }

        [TestMethod]
        public void TestRoutedEventName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarChangedEvent", dependencyProperty.RoutedEventName);
        }

        [TestMethod]
        public void TestStaticChangedMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarProperty_PropertyChanged", dependencyProperty.StaticChangedMethodName);
        }

        [TestMethod]
        public void TestStaticCoerceMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarProperty_CoerceProperty", dependencyProperty.StaticCoerceMethodName);
        }

        [TestMethod]
        public void TestStaticPartialValidateMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarProperty_ValidatePropertyImplementation", dependencyProperty.StaticPartialValidateMethodName);
        }

        [TestMethod]
        public void TestStaticValidateMethodName()
        {
            var config = CreateConfiguration();

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("BarProperty_ValidateProperty", dependencyProperty.StaticValidateMethodName);
        }

        [TestMethod]
        public void TestSummary()
        {
            var config = CreateConfiguration();
            config.Summary = "a summary";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("a summary", dependencyProperty.Summary);
        }

        [TestMethod]
        public void TestType()
        {
            var config = CreateConfiguration();
            config.Type = "bool";

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual("bool", dependencyProperty.Type);
        }

        [TestMethod]
        public void TestValidateValue()
        {
            var config = CreateConfiguration();
            config.ValidateValue = true;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(true, dependencyProperty.ValidateValue);
        }

        [TestMethod]
        public void TestVisibility()
        {
            var config = CreateConfiguration();
            config.Visibility = PropertyVisibility.Private;

            var dependencyProperty = new DependencyPropertyDataContext(config);

            Assert.AreEqual(PropertyVisibility.Private, dependencyProperty.Visibility);
        }

        private static MockDependencyPropertyConfiguration CreateConfiguration()
        {
            var config = new MockDependencyPropertyConfiguration();
            config.Name = "Bar";
            config.MetadataOptions = new List<string>();

            return config;
        }
    }
}
